package de.lindenvalley.ergo.view;

import java.util.Map;

import de.lindenvalley.ergo.R;
import de.lindenvalley.ergo.drag.DragActivity;
import de.lindenvalley.ergo.drag.DragController;
import de.lindenvalley.ergo.drag.DragLayer;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class GraphView extends View {
	
	private DragController dragController;

	public GraphView(Context context) {
		super(context);
	}

	public GraphView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public GraphView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Log.i(">>>>>>>>>", "onDraw()...........");
		super.onDraw(canvas);
		Path path = new Path();
		Paint paint = new Paint();
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(2f);
		paint.setColor(getResources().getColor(R.color.dummy_line_color));
		paint.setAntiAlias(true);
		int pointOffset = 0;
		View dragLayer = ((View)getParent());
		ImageView iv = (ImageView) dragLayer.findViewById(R.id.imageView2);
		if (iv != null){
			pointOffset = iv.getWidth() / 2;
		}
		if (dragController != null){
			Map<Integer,Point> points = dragController.getPoints();
			Point point = points.get(DragActivity.points[0]);
			path.moveTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[1]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[2]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[3]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[4]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[1]);
			path.moveTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[5]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
			point = points.get(DragActivity.points[6]);
			path.lineTo(point.x+pointOffset, point.y+pointOffset);
		}
//		ViewGroup parent = (ViewGroup) getParent();
//		View v = parent.findViewById(R.id.imageViewBigRound);
//		path.moveTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView2);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView3);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView4);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView5);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		
//		v = parent.findViewById(R.id.imageView2);
//		path.moveTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView6);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
//		v = parent.findViewById(R.id.imageView7);
//		path.lineTo(v.getLeft()+pointOffset, v.getTop()+pointOffset);
		canvas.drawPath(path, paint);
	}

	public void setDragController(DragController dragController) {
		this.dragController = dragController;
	}

	public DragController getDragController() {
		return dragController;
	}
	
	

}
